package com.example.justbuy.action.admin;

import com.example.justbuy.pojo.User;
import com.example.justbuy.service.UserDaoService;
import com.example.justbuy.util.MySqlMD5Until;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;

@Controller
@RequestMapping("/admin/")
public class AdminLoginAction {

    @Autowired
    UserDaoService userDaoService;

    /**
     * 登录页面
     * @return 登录页面
     */
    @RequestMapping("login.htm")
    public String login(){
        System.out.println("》》》》》》》》》》》》》》》》》》》》》》》》进入后台");
        return "admin/login.html";
    }

    /**
     * 后台验证登录首页
     * @return
     */
    @RequestMapping("main.htm")
    public String admin(String name, String pwd, HttpServletRequest request){
        HashMap map=new HashMap();;
        pwd= MySqlMD5Until.javamd5jm(pwd);
        map.put("name",name);
        map.put("pwd",pwd);
        map.put("roleid",3);
        User user=userDaoService.validateUser1(map);
        if(user==null){
            map.put("roleid",4);
            user=userDaoService.validateUser1(map);
        }
        if(user!=null){
            request.getSession().setAttribute("user1",user);
            return "admin/main.html";
        }else {
            return "admin/error.html";
        }
    }
    @RequestMapping("login1.htm")
    public String admin(HttpServletRequest request){
        request.getSession().removeAttribute("user1");
        return "admin/login.html";
    }
    /**
     * 拼接页面的左部
     * @return
     */
    @RequestMapping("left.htm")
    public String left(){
        return "admin/left.html";
    }

    /**
     * 拼接页面的头部
     * @return
     */
    @RequestMapping("top.htm")
    public String top(){
        return "admin/top.html";
    }

    /**
     * 拼接页面的右部
     * @return
     */
    @RequestMapping("index.htm")
    public String index(){
        return "admin/index.html";
    }
}
